package com.lin.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName:PageUnit
 * Package:com.lin.tools
 * Author: hellcat
 * Date: 2019/12/24
 * ♣♣♣
 */

public class PageUnit {
    public static Map<String, Object> Page(List list, int page, int limit) {
        Map<String, Object> map = new HashMap<>();
        if (list != null) {
            int count = list.size(); //记录总数
            int fromIndex = (page - 1) * limit;
            int toIndex = fromIndex + limit;
            if (toIndex > count) {
                toIndex = count;
            }
            List newList = list.subList(fromIndex, toIndex);
            map.put("code", true);
            map.put("msg", "");
            map.put("count", count);
            map.put("data", newList);
        } else {
            map.put("code", false);
            map.put("msg", "数据查询失败");
        }
        return map;

    }
}
